﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using TSVNAddin.SVN;
using Rhino.Mocks;

namespace TSVNAddin.Core.Test
{
	[TestFixture]
	public class WorkingRootFinderFixture
	{
		[Test]
		public void Found()
		{
			var svnClientAdapter = MockRepository.GenerateMock<SVNClientAdapter>();
			svnClientAdapter.Expect(x => x.GetInfo(@"c:\svnroot\myproject\trunk\newfolder\")).Return(null);

			svnClientAdapter.Expect(x => x.GetInfo(@"c:\svnroot\myproject\trunk\")).Return(
				new SVNInfoArgs()
				{
					RepositoryRoot = new Uri(@"http://localhost/svnroot/"),
					Uri = new Uri(@"http://localhost/svnroot/myproject/trunk/")
				}
			);

			var finder = new WorkingRootFinder(svnClientAdapter);
			string root = finder.FindRoot(@"c:\svnroot\myproject\trunk\newfolder\");

			Assert.AreEqual(@"c:\svnroot\", root);

			svnClientAdapter.VerifyAllExpectations();
		}

		[Test]
		public void DoesNotFound()
		{
			var svnClientAdapter = MockRepository.GenerateMock<SVNClientAdapter>();
			svnClientAdapter.Expect(x => x.GetInfo(@"c:\svnroot\myproject\trunk\newfolder\")).Return(null);
			svnClientAdapter.Expect(x => x.GetInfo(@"c:\svnroot\myproject\trunk\")).Return(null);
			svnClientAdapter.Expect(x => x.GetInfo(@"c:\svnroot\myproject\")).Return(null);
			svnClientAdapter.Expect(x => x.GetInfo(@"c:\svnroot\")).Return(null);
			svnClientAdapter.Expect(x => x.GetInfo(@"c:\")).Return(null);

			var finder = new WorkingRootFinder(svnClientAdapter);
			string root = finder.FindRoot(@"c:\svnroot\myproject\trunk\newfolder\");

			Assert.AreEqual(string.Empty, root);

			svnClientAdapter.VerifyAllExpectations();
		}
	}
}
